package com.unicom.microservice.peixun.peixun_demo1.web;

import com.unicom.microservice.peixun.peixun_demo1.domain.User;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : xuwenyuan
 * @date : 2019-11-8
 * @desc ：在Controller层实现  Users  RestFul  Api，并通过swagger详细说明接口
 */
@RestController
@RequestMapping("/peixun/demo1/")
public class UserController {


    /**
     * 查询所有用户
     * @return
     */
    @RequestMapping(value = "users", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有用户")
    public List<User> users(){
        List<User> userList = new ArrayList<>();
        User user1 = new User();
        user1.setName("zhangsan");
        user1.setAge(26);

        User user2 = new User();
        user2.setName("lisi");
        user2.setAge(18);

        userList.add(user1);
        userList.add(user2);
        return userList;
    }

    /**
     * 添加一个用户
     * @param user
     * @return
     */
    @RequestMapping(value = "users",method = RequestMethod.POST)
    @ApiOperation(value = "添加一个用户")
    public User saveuser(@RequestBody User user){
      return null;
    }


    /**
     * 根据ID查找用户
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查找用户")
    @RequestMapping(value = "users/{id}",method = RequestMethod.GET)
    public User findUserbyId(@PathVariable String id){
        return null;
    }

    /**
     * 根据ID定位用户并修改信息
     * @param id
     * @param user
     * @return
     */
    @ApiOperation(value = "根据ID定位用户并修改信息")
    @RequestMapping(value = "users/{id}",method = RequestMethod.PUT)
    public User updateUser(@PathVariable String id,@RequestBody User user){
        return null;
    }

    /**
     * 根据ID删除用户
     * @return
     */
    @ApiOperation(value = "根据ID删除用户")
    @RequestMapping(value = "users/{id}",method = RequestMethod.DELETE)
    public User delete(){
        return null;
    }

    /**
     * 根据姓名查找用户
     * @param name
     * @return
     */
    @ApiOperation(value = "根据姓名查找用户")
    @RequestMapping(value = "users/name/{name}",method = RequestMethod.GET)
    public List<User> findUsersByName(@PathVariable String name){
        return null;
    }

    /**
     * 根据ID查找用户的age
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查找用户的age")
    @RequestMapping(
            value = "users/{id}/age",
            method = RequestMethod.GET
    )
    public int findUserAgeById(@PathVariable String id){
        return 0;
    }



}

